package com.ruoyi.airsystem.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.airsystem.domain.AirPmlevels;
import com.ruoyi.airsystem.service.IAirPmlevelsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * PM浓度记录Controller

 * @date 2025-04-18
 */
@RestController
@RequestMapping("/airsystem/pmlevels")
public class AirPmlevelsController extends BaseController
{
    @Autowired
    private IAirPmlevelsService airPmlevelsService;

    /**
     * 查询PM浓度记录列表
     */
    @PreAuthorize("@ss.hasPermi('airsystem:pmlevels:list')")
    @GetMapping("/list")
    public TableDataInfo list(AirPmlevels airPmlevels)
    {
        startPage();
        List<AirPmlevels> list = airPmlevelsService.selectAirPmlevelsList(airPmlevels);
        return getDataTable(list);
    }

    /**
     * 导出PM浓度记录列表
     */
    @PreAuthorize("@ss.hasPermi('airsystem:pmlevels:export')")
    @Log(title = "PM浓度记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AirPmlevels airPmlevels)
    {
        List<AirPmlevels> list = airPmlevelsService.selectAirPmlevelsList(airPmlevels);
        ExcelUtil<AirPmlevels> util = new ExcelUtil<AirPmlevels>(AirPmlevels.class);
        util.exportExcel(response, list, "PM浓度记录数据");
    }

    /**
     * 获取PM浓度记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('airsystem:pmlevels:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(airPmlevelsService.selectAirPmlevelsByRecordId(recordId));
    }

    /**
     * 新增PM浓度记录
     */
    @PreAuthorize("@ss.hasPermi('airsystem:pmlevels:add')")
    @Log(title = "PM浓度记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AirPmlevels airPmlevels)
    {
        airPmlevelsService.checkAndInsertWarning(airPmlevels);
        return toAjax(airPmlevelsService.insertAirPmlevels(airPmlevels));
    }

    /**
     * 修改PM浓度记录
     */
    @PreAuthorize("@ss.hasPermi('airsystem:pmlevels:edit')")
    @Log(title = "PM浓度记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AirPmlevels airPmlevels)
    {
        return toAjax(airPmlevelsService.updateAirPmlevels(airPmlevels));
    }

    /**
     * 删除PM浓度记录
     */
    @PreAuthorize("@ss.hasPermi('airsystem:pmlevels:remove')")
    @Log(title = "PM浓度记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(airPmlevelsService.deleteAirPmlevelsByRecordIds(recordIds));
    }
}
